//
//  MainViewController.m
//  HTHappySale
//
//  Created by 创维海通 on 2017/9/15.
//  Copyright © 2017年 zxyywy. All rights reserved.
//

#import "MainViewController.h"
#import "EarningsViewController.h"
#import "MeViewController.h"

//Tools
#import "BaseNavigationController.h"

//View
#import "CustomTabBarView.h"

#define TABBAR_HEIGHT 64    //自定义UITabBar的高度

@interface MainViewController ()<CustomTabBarDelegate>
{
    //自定义tabBar视图
    CustomTabBarView *_tabBarView;
}
@property (nonatomic,strong) EarningsViewController *earningsVC;
@property (nonatomic,strong) MeViewController *meVC;

@end

@implementation MainViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor clearColor];
    
    //初始化tabBar
    [self initView];
    
    //初始化控制器
    [self initWithViewController];
    //    UIView *ui = [[self.view subviews] objectAtIndex:0];
    for (UIView *subView in self.view.subviews) {
        if ([subView isKindOfClass:NSClassFromString(@"UITransitionView")]) {
            subView.frame = CGRectMake(subView.frame.origin.x, subView.frame.origin.y, subView.frame.size.width, SCREEN_HEIGHT);
        }
    }
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:YES];
    self.tabBarController.tabBar.hidden = YES;
}

- (void)initView
{
    _tabBarView = [[CustomTabBarView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT-TABBAR_HEIGHT, SCREEN_WIDTH, TABBAR_HEIGHT)];
    _tabBarView.backgroundColor = HTCFQuickRGBColor(239, 239, 239);
    _tabBarView.tabBardelegate = self;
    
    [self.view addSubview:_tabBarView];
}

- (void)initWithViewController
{
    _earningsVC = [[EarningsViewController alloc] init];
    BaseNavigationController *earningsNac = [[BaseNavigationController alloc] initWithRootViewController:_earningsVC];
    
    _meVC = [[MeViewController alloc] init];
    BaseNavigationController *meNac = [[BaseNavigationController alloc] initWithRootViewController:_meVC];
    
    NSArray *ctrols = [NSArray arrayWithObjects:earningsNac,meNac,nil];
    self.viewControllers = ctrols;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark -private
- (void)showTabBar
{
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.35];
    _tabBarView.frame = CGRectMake(0, SCREEN_HEIGHT-TABBAR_HEIGHT, SCREEN_WIDTH, TABBAR_HEIGHT);
    [UIView commitAnimations];
}

- (void)hiddenTabBar
{
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.35];
    _tabBarView.frame = CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, TABBAR_HEIGHT);
    [UIView commitAnimations];
}

-(void)showTabBarWeb{
    _tabBarView.frame = CGRectMake(0, SCREEN_HEIGHT-TABBAR_HEIGHT, SCREEN_WIDTH, TABBAR_HEIGHT);
}
-(void)hiddenTabBarWeb{
    _tabBarView.frame = CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, TABBAR_HEIGHT);
}

#pragma mark -tabBarDelegate
-(void)selectController:(int)controllerId
{
    self.selectedIndex = controllerId - 100;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
    return NO;
}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
